<?php

/* 库存 */
class StorestockModel extends BaseModel
{
    var $table  = 'storestock';
    var $prikey = 'storestock_id';
    var $_name  = 'storestock';

    /* 添加编辑时自动验证 */
    var $_autov = array(
        'stock_name' => array(
            'required'  => true,    //必填
            'min'       => 1,       //最短1个字符
            'max'       => 100,     //最长100个字符
            'filter'    => 'trim',
        ),
    );
    /* 关系列表 */
//    var $_relation  = array(
//        // 一个仓库关系表只属于一个店铺
//        'belongs_to_goods' => array(
//            'model'             => 'store',
//            'type'              => BELONGS_TO,
//            'foreign_key'       => 'store_id',
//            'reverse'           => 'has_store',
//        ),
//    );
    function drop($conditions, $fields = 'stock_name')
    {
        $droped_rows = parent::drop($conditions, $fields);
        if ($droped_rows)
        {
            restore_error_handler();
            $droped_data = $this->getDroppedData();
            foreach ($droped_data as $key => $value)
            {
                if ($value['ad_logo'])
                {
                    @unlink(ROOT_PATH . '/' . $value['stock_name']);  //删除Logo文件
                }
            }
            reset_error_handler();
        }

        /**
         * 取得信息
         */
        function get_info($adminstock_id)
        {
            $info = $this->get(array(
                'conditions' => $adminstock_id,
            ));
            if (!empty($info['certification']))
            {
                $info['certifications'] = explode(',', $info['certification']);
            }
            return $info;
        }
        return $droped_rows;
    }

}

?>